package com.joyintech.condition;

import java.math.BigDecimal;
import java.util.Map;

//规则条件类
public class RuleCondition {
    private BigDecimal actualValue;    //指标值
    private String operator;      // 操作符（>, <, >=, <=, =, !=）
    private BigDecimal thresholdValue;     // 阈值
    private String metricName;//
    private String key;//方案ID
    private Map<String, String> codeToNameMap;// 字段名称
    public RuleCondition(BigDecimal actualValue, String operator, BigDecimal thresholdValue,String metricName,String key, Map<String, String> codeToNameMap) {
        this.actualValue = actualValue;
        this.operator = operator;
        this.thresholdValue = thresholdValue;
        this.metricName = metricName;
        this.key = key;
        this.codeToNameMap = codeToNameMap;
    }

    /**
     * 评估条件是否满足
     *
     * @return 条件是否满足
     */
    public boolean evaluate() {
        // 实际应用中，这里需要获取字段的实际值
//        double actualValue = getFieldValue(field);

        switch (operator) {
            case ">":
                 return actualValue.compareTo(thresholdValue) > 0;
            case "<":
                return actualValue.compareTo(thresholdValue) < 0;
            case ">=":
                return actualValue.compareTo(thresholdValue) >= 0;
            case "<=":
                return actualValue.compareTo(thresholdValue) <= 0;
            case "=":
                return actualValue.compareTo(thresholdValue) == 0;
            default:
                return false;
        }
    }

    public BigDecimal getActualValue() {
        return actualValue;
    }

    public void setActualValue(BigDecimal actualValue) {
        this.actualValue = actualValue;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public BigDecimal getThresholdValue() {
        return thresholdValue;
    }

    public void setThresholdValue(BigDecimal thresholdValue) {
        this.thresholdValue = thresholdValue;
    }

    public String getMetricName() {
        return metricName;
    }

    public void setMetricName(String metricName) {
        this.metricName = metricName;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Map<String, String> getCodeToNameMap() {
        return codeToNameMap;
    }

    public void setCodeToNameMap(Map<String, String> codeToNameMap) {
        this.codeToNameMap = codeToNameMap;
    }

    /**
     * 获取字段的实际值（示例方法）
     *
     * @param fieldName 字段名称
     * @return 字段值
     */
//    private double getFieldValue(String fieldName) {
//        // 这里应该是从实际数据源获取值的逻辑
//        // 示例实现
//        switch (fieldName) {
//            case "周期检视":
//                return 60; // 示例值
//            case "固定类满意度":
//                return 55; // 示例值
//            case "现实类满意度":
//                return 90; // 示例值
//            default:
//                return 0;
//        }
//    }
}
